<template>
    <div class="entrance">
        <div class="loginHeader">
            <el-image class="img" :src="require('@/assets/images/icon/logo1.png')" fit="contain" />
            <div class="links">
                <el-button type="info" link class="btnBox-btn">首页</el-button>
                <el-button type="info" link class="btnBox-btn">文档</el-button>
                <el-button type="info" link class="btnBox-btn">开发者</el-button>
            </div>
        </div>
        <div class="entranceCont">
            <div class="leftImages">
                <!-- <div class="leftImages-text">
                    <h2>柑橘采摘季</h2>
                    <p>认证或付费可参获赠精品纽荷尔1件</p>
                </div> -->
                <!-- <el-image :src="require('@/assets/image/loginbg.png')" class="leftImages-img"></el-image> -->
                <!-- <el-image :src="require('@/assets/image/bgImg.png')" class="leftImages-img"></el-image> -->
            </div>
            <div class="loginBox">
                <div class="boxtitle">
                    <div class="boxtitleItem selecttitle">用户登录</div>
                    <div class="boxtitleItem">二维码登录</div>
                </div>
                <div class="boxform">
                    <div class="formTitle">云上农场账号登录</div>
                    <input type="text" class="forminputs" autocomplete="off" v-model="formInline.name" name="" placeholder="手机号/ 邮箱地址/账号名" id="name" />
                    <input type="password" class="forminputs" autocomplete="off" v-model="formInline.pwd" @keyup.enter.native="onSubmit" name="" placeholder="密码" id="pwd" />
                    <div class="submitBtn" @click="onSubmit">登录</div>
                    <!-- <el-form :model="formInline" size="large" class="demo-form-inline">
                        <el-form-item label="">
                            <el-input v-model="formInline.name" autocomplete="off" clearable placeholder="手机号/ 邮箱地址/账号名" />
                        </el-form-item>
                        <el-form-item label="">
                            <el-input v-model="formInline.pwd" autocomplete="off" clearable @keyup.enter.native="onSubmit" type="password" placeholder="密码" />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" class="submitBtn" @click="onSubmit">登录</el-button>
                        </el-form-item>
                    </el-form> -->
                    <div class="toelsepage">
                        <el-button type="info" class="toelsepagebtn" link @click="toelsepages('/register')">注册</el-button><span>丨</span>
                        <el-button type="info" class="toelsepagebtn" link @click="toelsepages('/retrieve')">忘记密码</el-button>
                    </div>
                    <div class="logintip">我们为您提供云上农场帐号服务，在登录过程中会使用到您的帐号和网络信 息提升登录体验。</div>
                </div>
            </div>
        </div>
        <div class="entranceFooter">
            <div class="copyright">
                © 2009-2022szfarm.com 重庆三峡农夫科技有限公司 版权所有
                <p>网站备案：渝ICP备2020013911号 <span> 渝公网安备XXX号</span></p>
            </div>
            <span class="copyrightbtn">
                <span class="btnBox-btn">用户协议</span>
                <span class="btnBox-btn">隐私声明</span>
            </span>
            <!-- <div>
                <span class="btnBox-btn">用户协议</span>
                <span class="btnBox-btn">隐私声明</span>
            </div> -->
        </div>
    </div>
</template>
<script lang="ts" setup>
import { Md5 } from "ts-md5";
import { reactive, inject, ref } from "vue";
import { useRouter } from "vue-router";
import { getUserInfo } from "@/api/user";
import { login } from "@/api/auth";
import { ElMessage } from "element-plus";
import { useStore } from "vuex";
// const md5: any = new Md5();
const router = useRouter();
const store = useStore();
const formInline = reactive({
    name: "",
    pwd: "",
});
const toelsepages = (u: string) => {
    router.push(u);
};
const onSubmit = () => {
    if (!formInline.name) {
        ElMessage.error("请输入正确的账号");
        return;
    }
    if (!formInline.pwd) {
        ElMessage.error("密码不能为空");
        return;
    }
    const md5: any = new Md5();
    // console.log(formInline);
    md5.appendAsciiStr(formInline.pwd);

    const password = md5.end();

    const postData = {
        principal: formInline.name,
        credentials: password,
        sysType: 0,
    };
    // router.replace("/");
    // store.commit("setToken", "321");
    // return;
    login(postData)
        .then((res) => {
            console.log(res);
            store.commit("setToken", res.data.accessToken);
            getUserInfo().then((res: any) => {
                store.commit("setUserInfo", res.data);
            });
            router.replace("/");
        })
        .catch((e) => {
            // password.value = "";
        });
};
</script>
<style lang="scss" scoped>
.loginHeader {
    width: 100%;
    height: 0.45rem;
    background: #ffffff;
    padding: 0 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 0 0.12rem 0 rgb(0 0 0 / 30%);
    .img {
        // width: 1rem;
        height: 0.4rem;
    }
    .links {
        display: flex;
        justify-content: flex-end;
        align-items: center;

        .btnBox-btn {
            margin-left: 0.2rem;
            font-size: 0.14rem;
        }
    }
}
.entranceCont {
    //background: url(@/assets/image/bgImg.png) 80% / cover no-repeat;
    background-image: url(@/assets/image/bgImg.png);
    width: 100%;
    height: calc(100vh - 1.15rem);
    background-repeat: no-repeat;
    background-size: 110% calc(110vw / 2.9);
    background-position: -1.8rem;
    display: flex;
    //justify-content: center;
    justify-content: space-between;
    align-items: center;
    .leftImages {
        font-size: 0.3rem;
        text-align: center;
        margin-right: 2.6rem;
        p {
            margin-top: 0.2rem;
            margin-bottom: 0.45rem;
            font-size: 0.24rem;
        }
        .leftImages-img {
            width: 3.94rem;
            height: 3.35rem;
        }
    }
    .loginBox {
        width: 4.2rem;
        height: 5.5rem;
        background: #ffffff;
        border-radius: 0.06rem;
        overflow: hidden;
        margin-right: 3.5rem;
        margin-top: -0.7rem;
        // margin-right: calc(100vw * 0.05);
        box-shadow: 0 0 0.12rem 0 rgba(0, 0, 0, 0.2);
        // transform: scale(0.85);
        .boxtitle {
            width: 100%;
            height: 0.77rem;
            line-height: 0.77rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            .boxtitleItem {
                width: 50%;
                text-align: center;
                font-size: 0.18rem;
                color: #999999;
                cursor: pointer;
                border-bottom: 0.01rem solid rgba(0, 0, 0, 0);
            }
            .selecttitle {
                color: #333333;
                border-bottom: 0.01rem solid #23b14d;
            }
        }
        .boxform {
            padding: 0.4rem;
            .formTitle {
                font-size: 0.24rem;
                padding-bottom: 0.4rem;
                text-align: center;
            }
            .forminputs {
                width: 100%;
                border: 0.01rem solid #dcdfe6;
                height: 0.48rem;
                border-radius: 0.05rem;
                padding: 0.01rem 0.15rem;
                font-size: 0.14rem;
                margin-bottom: 0.24rem;
                overflow: hidden;
                &:hover,
                &:focus {
                    border-color: #24b14e;
                }
                &::-webkit-input-placeholder {
                    font-size: 0.14rem;
                    color: #c8c9cc;
                }
            }
            .submitBtn {
                width: 100%;
                height: 0.48rem;
                background-color: #24b14e;
                text-align: center;
                line-height: 0.48rem;
                border-radius: 0.05rem;
                cursor: pointer;
                color: #ffffff;
                font-size: 0.14rem;
            }
        }
        .toelsepage {
            color: #999999;
            display: flex;
            justify-content: center;
            align-items: center;
            padding-top: 0.18rem;
            font-size: 0.14rem;
            .toelsepagebtn {
                font-size: 0.14rem;
            }
        }
        .logintip {
            margin-top: 0.4rem;
            font-size: 0.12rem;
            color: #999999;
        }
    }
}
.entranceFooter {
    width: 100%;
    height: 0.7rem;
    background: #ffffff;
    padding: 0.2rem 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .copyright {
        font-size: 0.12rem;
        span {
            margin-left: 0.2rem;
        }
    }
    .copyrightbtn {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .btnBox-btn {
        font-size: 0.14rem;
        color: #999999;
        // line-height: 0.7rem;
        cursor: pointer;
        margin-left: 0.15rem;
    }
}
</style>
